<% layout('/layouts/default.html', {title: '报关通知管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(tdeclarationNotice.isNewRecord ? '新增报关通知' : '编辑报关通知')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${tdeclarationNotice}" action="${ctx}/financial/declarationnotice/tdeclarationNotice/save" method="post" class="form-horizontal">
		<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="customsDeclarationNoticeId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customsDeclarationNoticeCode" readonly="true" placeholder="自动编号" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
				<#form:hidden path="isNotice"/>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="customerId" items="${listCustomer}"
								itemLabel="customerName" itemValue="customerId" required="true" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="serviceOrderId" items="${listOrder}" id="serviceOrderId"
								itemLabel="serviceOrderCode" itemValue="serviceOrderId" required="true" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('报关行')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="customsBroker" items="${listSupplier}"
								itemLabel="supplierName" itemValue="supplierId" required="true" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('提单编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="ladingBillId" items="${listLadingbill}"
								itemLabel="ladingBillCode" itemValue="ladingBillId" required="true"  blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('报关单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customsDeclarationCode"  readonly="true" maxlength="100" class="form-control"/>
							</div>
							</div>
						</div>
					</div>
			    <div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('目的港')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="toPort" dictType="erp_harbor_list"  blankOption="true" enable="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外贸合同号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="foreignTradeContractNumber"  readonly="true" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('采购委托书号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="purchaseCommissionNumber"  readonly="true" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('通知日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="date" readonly="true" maxlength="20" class="form-control laydate" disabled="true"
									dataFormat="date" data-type="date"  readonly="true" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('已全部上传')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="allUploadFlag" dictType="sys_yes_no" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('图片上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadImage" bizKey="${tdeclarationNotice.id}" bizType="tdeclarationNotice_image"
									uploadType="image" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${tdeclarationNotice.id}" bizType="tdeclarationNotice_file"
									uploadType="all" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('报关通知清单')}</h4>
				<div class="ml10 mr10">
					<table id="tdeclarationNoticeListDataGrid"></table>
					<!--<% if (hasPermi('financial:declarationnotice:tdeclarationNotice:edit')){ %>
						<a href="#" id="tdeclarationNoticeListDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>-->
				</div>
				<h4 class="form-unit">${text('报关通知明细')}</h4>
				<div class="ml10 mr10">
					<table id="tdeclarationNoticeDetailDataGrid"></table>
					<!--<% if (hasPermi('financial:declarationnotice:tdeclarationNotice:edit')){ %>
						<a href="#" id="tdeclarationNoticeDetailDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>-->
				</div>
			<div class="form-unit">${text('系统信息')}</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="createDate" class="form-control" disabled="true"
							dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<!--<#form:input path="createBy" class="form-control" disabled="true"/>-->
							<#form:select path="createBy" items="${listUser}" disabled="true"
							itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
							dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<!--<#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>-->
							<#form:select path="updateBy" items="${listUser}" disabled="true"
							itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
						</div>
					</div>
				</div>
			</div>

		</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('financial:declarationnotice:tdeclarationNotice:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>

	</div>
</div>
<% } %>
<script>
//初始化报关通知清单DataGrid对象
$("#tdeclarationNoticeListDataGrid").dataGrid({
	data: ${toJson(tdeclarationNotice.tdeclarationNoticeListList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'customsDeclarationNoticeListId', editable:true, hidden:true},
		{header:'${text("资料名称")}', name:'data', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100','readonly':'true', 'class':'form-control'}},
		{header:'${text("报关通知ID")}', name:'customsDeclarationNoticeId.customsDeclarationNoticeId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
				var actions = [];
				if (val == 'new'){
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tdeclarationNoticeListDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}else{
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tdeclarationNoticeListDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}
				return actions.join('');
			}, editoptions: {defaultValue: 'new'}}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tdeclarationNoticeListDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {customsDeclarationNoticeListId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tdeclarationNoticeListList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,customsDeclarationNoticeListId,data,customsDeclarationNoticeId.customsDeclarationNoticeId', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
//初始化报关通知明细DataGrid对象
$("#tdeclarationNoticeDetailDataGrid").dataGrid({
	data: ${toJson(tdeclarationNotice.tdeclarationNoticeDetailList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'customsDeclarationNoticeDetailId', editable:true, hidden:true},
		{header:'${text("车架号")}', name:'frameNumber', width:100,editable:true,edittype:'text', editoptions:{'maxlength':'100','readonly':'true', 'class':'form-control'}},
		{header:'${text("行号")}', name:'rowNumber', width:100,editable:true,edittype:'text', editoptions:{'maxlength':'100','readonly':'true', 'class':'form-control'}},
		{header:'${text("车辆")}', name:'carId', width:100,editable:true,edittype:'text', editoptions:{'maxlength':'100','readonly':'true', 'class':'form-control'}},
		{header:'${text("品牌")}', name:'brand', width:100,
			editable:true, edittype:'select', editoptions:{'class':'form-control','readonly':true,
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('car_pinpai')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("版型")}', name:'area', width:100,
			editable:true, edittype:'select', editoptions:{'class':'form-control','readonly':'true',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('car_quyu')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("车型")}', name:'model', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100','readonly':'true', 'class':'form-control'}},
		{header:'${text("报关通知ID")}', name:'customsDeclarationNoticeId.customsDeclarationNoticeId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
				var actions = [];
				if (val == 'new'){
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tdeclarationNoticeDetailDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}else{
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tdeclarationNoticeDetailDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}
				return actions.join('');
			}, editoptions: {defaultValue: 'new'}}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tdeclarationNoticeDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {customsDeclarationNoticeDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tdeclarationNoticeDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,customsDeclarationNoticeDetailId,frameNumber,carId,brand,area,model,customsDeclarationNoticeId.customsDeclarationNoticeId,rowNumber', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
</script>
<script>
$("#serviceOrderId").change(function(){
	var serviceOrderId=$("#serviceOrderId").val();
	var items=[];
	var List=[];
	var areas=[];//版型
	$.post('${ctx}/financial/declarationnotice/tdeclarationNotice/getServiceOrderById?serviceOrderId='+serviceOrderId,null, function (data) {
		$("#customerId").val(data.serviceOrder.customer.customerId).trigger('change');
		$("#toPort").val(data.serviceOrder.toPort).trigger('change');
		$("#foreignTradeContractNumber").val(data.serviceOrder.foreignTradeContractNumber);
		$("#purchaseCommissionNumber").val(data.serviceOrder.purchaseCommissionNumber);
		var itemcount = data.serviceOrder.serviceOrderDetailList.length;
		var allIds = $('#tdeclarationNoticeDetailDataGrid').dataGrid('getDataIDs');
		for (var i = 0; i < allIds.length; i++) {
			$('#tdeclarationNoticeDetailDataGrid').dataGrid('delRowData', allIds[i]);
		}
		for (var i = 0; i < itemcount; i++) {
			if (data.serviceOrder.serviceOrderDetailList[i].area&&data.serviceOrder.serviceOrderDetailList[i].area != '') {
				areas.push(data.serviceOrder.serviceOrderDetailList[i].area);
			}
			if (data.serviceOrder.serviceOrderDetailList[i].frameNumber){
				items.push({
					'frameNumber': data.serviceOrder.serviceOrderDetailList[i].frameNumber,
					'rowNumber': data.serviceOrder.serviceOrderDetailList[i].rowNumber,
					'carId': data.serviceOrder.serviceOrderDetailList[i].carId,
					'brand': data.serviceOrder.serviceOrderDetailList[i].brand,
					'area': data.serviceOrder.serviceOrderDetailList[i].area,
					'model': data.serviceOrder.serviceOrderDetailList[i].model,
				});
			}
		}
		$("#tdeclarationNoticeDetailDataGrid").jqGrid('setGridParam', {data: items});
		$("#tdeclarationNoticeDetailDataGrid")[0].grid.endReq();
		$("#tdeclarationNoticeDetailDataGrid").trigger('reloadGrid');

		var toPort = $("#toPort").val();
		areas=Array.from(new Set(areas));
		if (areas && toPort) {
			$.post('${ctx}/financial/declarationnotice/tdeclarationNotice/getNoticeList?toPort='+toPort+'&areas='+areas,null, function (data) {
				for(var d=0;d<data.customsDeclarationInfoDetailList.length;d++){
					List.push({'data':data.customsDeclarationInfoDetailList[d].infoName});
				}
				$("#tdeclarationNoticeListDataGrid").jqGrid('setGridParam', {data: List});
				$("#tdeclarationNoticeListDataGrid")[0].grid.endReq();
				$("#tdeclarationNoticeListDataGrid").trigger('reloadGrid');
			});
		}
	});
});

$("#inputForm").validate({
	submitHandler: function(form){

		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
	}
});
</script>
